# -*- coding: utf-8 -*-
# @Time        :2025/3/10 21:36
# @Author      :文刀水寿
# @File        : 25_爬虫_selenium_为什么要学习selenium.py
"""
 @Description :  1.Selenium
                 2.Phantomjs
                 3.Chrome handless
"""
"""
Selenium
    1.什么是selenium？ 
    (1) selenium是一个用于web应用程序测试的工具。 
    (2)selenium测试直接运行在浏览器中，就像真正的用户在操作一样。 
    (3)支持通过各种driver(FirfoxDriver,IternetExplorerDriver, operaDriver, ChromeDriver)驱动
    真实浏览器完成测试。 
    (4)selenium也是支持无界面浏览器操作的。 
    
    2.为什么使用selenium？ 
    模拟浏览器功能，自动执行网页中的js代码，实现动态加载
    
    3.如何安装selenium？ 
    (1)操作谷歌浏览器驱动下载地址
    http://chromedriver.storage.googleapis.com/index.html 
    (2)谷歌驱动和谷歌浏览器版本之间的映射表
    http://blog.csdn. net/huilan same/article/details/51896672 
    (3)查看谷歌浏览器版本
    谷歌浏览器右上角-->帮助-->关于
    (4) pip install selenium 
    
    4.selenium的使用步骤？ 
    (1)导入:from selenium import webdriver (2)创建谷歌浏览器操作对象: 
    path=谷歌浏览器驱动文件路径browser = webdriver.Chrome (path)
"""
import urllib.request

url = 'https://www.jd.com/?'

headers = {
    'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
    'accept-language': 'zh-CN,zh;q=0.9',
    'cookie': 'unpl=JF8EAJpnNSttDBtcDR4EGUJCGFwAW1gAGR8HPDdXAQgMT1dXSFdOExR7XlVdWRRKFR9vZxRUXFNIVQ4bBSsSEXteU11bD00VB2xXVgQFDQ8WUUtBSUt-S1tXV1QOSh4AbGQBZG1bS2QFGjIbFhlCXVJfWgBNJwJfYDVkbVpIVAITBysTIEptFgoBDUIUAm9jSFRZUUJUAxoFExQgSm1X; __jdv=229668127|baidu-search|t_262767352_baidusearch|cpc|172887082225_0_ea99473acb0e449c95bacdde52cbdd05|1741659616659; __jdu=1588170697; 3AB9D23F7A4B3C9B=M3P7EXXTXFIH7WMDB435RINZ55BXYQOHQJCSDJX47TQHDYZOS2KDXUQPTAMK4SGCXQCUJV35DCTZ6JOZZ2GBUC6F4I; __jda=76161171.1588170697.1741659615.1741659615.1741659617.1; __jdc=76161171; 3AB9D23F7A4B3CSS=jdd03M3P7EXXTXFIH7WMDB435RINZ55BXYQOHQJCSDJX47TQHDYZOS2KDXUQPTAMK4SGCXQCUJV35DCTZ6JOZZ2GBUC6F4IAAAAMVQMAOPBYAAAAADGWDZJPUSQRVCMX; _gia_d=1; areaId=27; ipLoc-djd=27-2442-0-0; PCSYCityID=CN_610000_610700_0; shshshfpa=7cad0837-bb2f-15c5-b38b-e4a385c69ea5-1741659631; shshshfpx=7cad0837-bb2f-15c5-b38b-e4a385c69ea5-1741659631; sdtoken=AAbEsBpEIOVjqTAKCQtvQu1759E7IGXiycRkZvtP35BjFlvRxYBqZGKIR97qnwGjbeeObiriEfpatqdS4Y8_vQZLS6u5n11vX0DAJNWD4drkM06ZBVBLRO-s7B5Kwaub8Tc; shshshfpb=BApXSt5gJgPBAW6YnSWj7cQFCjdQ-AC9_BgMkkR5o9xJ1Mkum0oG2; __jdb=76161171.3.1588170697|1.1741659617',
    'priority': 'u=0, i',
    'referer': 'https://www.jd.com/',
    'sec-ch-ua-mobile': '?1',
    'sec-ch-ua-platform': '"Android"',
    'sec-fetch-dest': 'document',
    'sec-fetch-mode': 'navigate',
    'sec-fetch-site': 'same-site',
    'upgrade-insecure-requests': '1',
    'user-agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Mobile Safari/537.36 Edg/134.0.0.0',
}

request = urllib.request.Request(url=url, headers=headers)

response = urllib.request.urlopen(request)

content = response.read().decode('utf-8')

print(content)
